package by.bsu.touragency.command.guest;

import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import by.bsu.touragency.command.Command;

public class AllNBToursCommand implements Command {

	private static Logger logger = Logger.getLogger("log");
	private static final String PARAM_SEARCH_TEXT = "text";

	public String execute(HttpServletRequest request){

		logger.info("All NOT booked tours");
		String page = null;
		String text = request.getParameter(PARAM_SEARCH_TEXT);
		if (AllNBToursLogic.checkSearch(text)) {

			request.setAttribute("tours", AllNBToursLogic.getTours().get(0)
					.getPrice());
			page = ConfigurationManager.getInstance().getProperty(
					ConfigurationManager.MAIN_PAGE_PATH);
			logger.debug("go to index.jsp");
		} else {
			request.setAttribute("errorMessage", MessageManager.getInstance()
					.getProperty(MessageManager.LOGIN_ERROR_MESSAGE));
			page = ConfigurationManager.getInstance().getProperty(
					ConfigurationManager.ERROR_PAGE_PATH);
			logger.error("Error in the search");
		}
		return page;
	}

}
